home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / man.n / format.n < prev    next >
Text File  |  1995-07-17  |  13KB  |  415 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/format.n,v 1.4 93/08/05 13:56:19 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .\" The definitions below are for supplemental macros used in Tcl/Tk
  24. .\" manual entries.
  25. .\"
  26. .\" .HS name section [date [version]]
  27. .\"    Replacement for .TH in other man pages.  See below for valid
  28. .\"    section names.
  29. .\"
  30. .\" .AP type name in/out [indent]
  31. .\"    Start paragraph describing an argument to a library procedure.
  32. .\"    type is type of argument (int, etc.), in/out is either "in", "out",
  33. .\"    or "in/out" to describe whether procedure reads or modifies arg,
  34. .\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  35. .\"    needed;  use .AS below instead)
  36. .\"
  37. .\" .AS [type [name]]
  38. .\"    Give maximum sizes of arguments for setting tab stops.  Type and
  39. .\"    name are examples of largest possible arguments that will be passed
  40. .\"    to .AP later.  If args are omitted, default tab stops are used.
  41. .\"
  42. .\" .BS
  43. .\"    Start box enclosure.  From here until next .BE, everything will be
  44. .\"    enclosed in one large box.
  45. .\"
  46. .\" .BE
  47. .\"    End of box enclosure.
  48. .\"
  49. .\" .VS
  50. .\"    Begin vertical sidebar, for use in marking newly-changed parts
  51. .\"    of man pages.
  52. .\"
  53. .\" .VE
  54. .\"    End of vertical sidebar.
  55. .\"
  56. .\" .DS
  57. .\"    Begin an indented unfilled display.
  58. .\"
  59. .\" .DE
  60. .\"    End of indented unfilled display.
  61. .\"
  62. '\"    # Heading for Tcl/Tk man pages
  63. .de HS
  64. .ds ^3 \\0
  65. .if !"\\$3"" .ds ^3 \\$3
  66. .if '\\$2'cmds'       .TH \\$1 1 \\*(^3 \\$4
  67. .if '\\$2'lib'        .TH \\$1 3 \\*(^3 \\$4
  68. .if '\\$2'tcl'        .TH \\$1 n \\*(^3 Tcl "Tcl Built-In Commands"
  69. .if '\\$2'tk'         .TH \\$1 n \\*(^3 Tk "Tk Commands"
  70. .if '\\$2'tclc'        .TH \\$1 3 \\*(^3 Tcl "Tcl Library Procedures"
  71. .if '\\$2'tkc'         .TH \\$1 3 \\*(^3 Tk "Tk Library Procedures"
  72. .if '\\$2'tclcmds'         .TH \\$1 1 \\*(^3 Tk "Tcl Applications"
  73. .if '\\$2'tkcmds'         .TH \\$1 1 \\*(^3 Tk "Tk Applications"
  74. .if t .wh -1.3i ^B
  75. .nr ^l \\n(.l
  76. .ad b
  77. ..
  78. '\"    # Start an argument description
  79. .de AP
  80. .ie !"\\$4"" .TP \\$4
  81. .el \{\
  82. .   ie !"\\$2"" .TP \\n()Cu
  83. .   el          .TP 15
  84. .\}
  85. .ie !"\\$3"" \{\
  86. .ta \\n()Au \\n()Bu
  87. \&\\$1    \\fI\\$2\\fP    (\\$3)
  88. .\".b
  89. .\}
  90. .el \{\
  91. .br
  92. .ie !"\\$2"" \{\
  93. \&\\$1    \\fI\\$2\\fP
  94. .\}
  95. .el \{\
  96. \&\\fI\\$1\\fP
  97. .\}
  98. .\}
  99. ..
  100. '\"    # define tabbing values for .AP
  101. .de AS
  102. .nr )A 10n
  103. .if !"\\$1"" .nr )A \\w'\\$1'u+3n
  104. .nr )B \\n()Au+15n
  105. .\"
  106. .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  107. .nr )C \\n()Bu+\\w'(in/out)'u+2n
  108. ..
  109. '\"    # BS - start boxed text
  110. '\"    # ^y = starting y location
  111. '\"    # ^b = 1
  112. .de BS
  113. .br
  114. .mk ^y
  115. .nr ^b 1u
  116. .if n .nf
  117. .if n .ti 0
  118. .if n \l'\\n(.lu\(ul'
  119. .if n .fi
  120. ..
  121. '\"    # BE - end boxed text (draw box now)
  122. .de BE
  123. .nf
  124. .ti 0
  125. .mk ^t
  126. .ie n \l'\\n(^lu\(ul'
  127. .el \{\
  128. .\"    Draw four-sided box normally, but don't draw top of
  129. .\"    box if the box started on an earlier page.
  130. .ie !\\n(^b-1 \{\
  131. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  132. .\}
  133. .el \}\
  134. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  135. .\}
  136. .\}
  137. .fi
  138. .br
  139. .nr ^b 0
  140. ..
  141. '\"    # VS - start vertical sidebar
  142. '\"    # ^Y = starting y location
  143. '\"    # ^v = 1 (for troff;  for nroff this doesn't matter)
  144. .de VS
  145. .mk ^Y
  146. .ie n 'mc \s12\(br\s0
  147. .el .nr ^v 1u
  148. ..
  149. '\"    # VE - end of vertical sidebar
  150. .de VE
  151. .ie n 'mc
  152. .el \{\
  153. .ev 2
  154. .nf
  155. .ti 0
  156. .mk ^t
  157. \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  158. .sp -1
  159. .fi
  160. .ev
  161. .\}
  162. .nr ^v 0
  163. ..
  164. '\"    # Special macro to handle page bottom:  finish off current
  165. '\"    # box/sidebar if in box/sidebar mode, then invoked standard
  166. '\"    # page bottom macro.
  167. .de ^B
  168. .ev 2
  169. 'ti 0
  170. 'nf
  171. .mk ^t
  172. .if \\n(^b \{\
  173. .\"    Draw three-sided box if this is the box's first page,
  174. .\"    draw two sides but no top otherwise.
  175. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  176. .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  177. .\}
  178. .if \\n(^v \{\
  179. .nr ^x \\n(^tu+1v-\\n(^Yu
  180. \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  181. .\}
  182. .bp
  183. 'fi
  184. .ev
  185. .if \\n(^b \{\
  186. .mk ^y
  187. .nr ^b 2
  188. .\}
  189. .if \\n(^v \{\
  190. .mk ^Y
  191. .\}
  192. ..
  193. '\"    # DS - begin display
  194. .de DS
  195. .RS
  196. .nf
  197. .sp
  198. ..
  199. '\"    # DE - end display
  200. .de DE
  201. .fi
  202. .RE
  203. .sp .5
  204. ..
  205. .HS format tcl
  206. .BS
  207. '\" Note:  do not modify the .SH NAME line immediately below!
  208. .SH NAME
  209. format \- Format a string in the style of sprintf
  210. .SH SYNOPSIS
  211. \fBformat \fIformatString \fR?\fIarg arg ...\fR?
  212. .BE
  213.  
  214. .SH INTRODUCTION
  215. .PP
  216. This command generates a formatted string in the same way as the
  217. ANSI C \fBsprintf\fR procedure (it uses \fBsprintf\fR in its
  218. implementation).
  219. \fIFormatString\fR indicates how to format the result, using
  220. \fB%\fR conversion specifiers as in \fBsprintf\fR, and the additional
  221. arguments, if any, provide values to be substituted into the result.
  222. The return value from \fBformat\fR is the formatted string.
  223.  
  224. .SH "DETAILS ON FORMATTING"
  225. .PP
  226. The command operates by scanning \fIformatString\fR from left to right. 
  227. Each character from the format string is appended to the result
  228. string unless it is a percent sign.
  229. If the character is a \fB%\fR then it is not copied to the result string.
  230. Instead, the characters following the \fB%\fR character are treated as
  231. a conversion specifier.
  232. The conversion specifier controls the conversion of the next successive
  233. \fIarg\fR to a particular format and the result is appended to 
  234. the result string in place of the conversion specifier.
  235. If there are multiple conversion specifiers in the format string,
  236. then each one controls the conversion of one additional \fIarg\fR.
  237. The \fBformat\fR command must be given enough \fIarg\fRs to meet the needs
  238. of all of the conversion specifiers in \fIformatString\fR.
  239. .PP
  240. Each conversion specifier may contain up to six different parts:
  241. .VS
  242. an XPG3 position specifier,
  243. .VE
  244. a set of flags, a minimum field width, a precision, a length modifier,
  245. and a conversion character.
  246. Any of these fields may be omitted except for the conversion character.
  247. The fields that are present must appear in the order given above.
  248. The paragraphs below discuss each of these fields in turn.
  249. .PP
  250. .VS
  251. If the \fB%\fR is followed by a decimal number and a \fB$\fR, as in
  252. ``\fB%2$d\fR'', then the value to convert is not taken from the
  253. next sequential argument.
  254. Instead, it is taken from the argument indicated by the number,
  255. where 1 corresponds to the first \fIarg\fR.
  256. If the conversion specifier requires multiple arguments because
  257. of \fB*\fR characters in the specifier then
  258. successive arguments are used, starting with the argument
  259. given by the number.
  260. This follows the XPG3 conventions for positional specifiers.
  261. If there are any positional specifiers in \fIformatString\fR
  262. then all of the specifiers must be positional.
  263. .VE
  264. .PP
  265. The second portion of a conversion specifier may contain any of the
  266. following flag characters, in any order:
  267. .TP 10
  268. \fB\-\fR
  269. Specifies that the converted argument should be left-justified 
  270. in its field (numbers are normally right-justified with leading 
  271. spaces if needed).
  272. .TP 10
  273. \fB+\fR
  274. Specifies that a number should always be printed with a sign, 
  275. even if positive.
  276. .TP 10
  277. \fIspace\fR
  278. Specifies that a space should be added to the beginning of the 
  279. number if the first character isn't a sign.
  280. .TP 10
  281. \fB0\fR
  282. Specifies that the number should be padded on the left with 
  283. zeroes instead of spaces.
  284. .TP 10
  285. \fB#\fR
  286. Requests an alternate output form. For \fBo\fR and \fBO\fR
  287. conversions it guarantees that the first digit is always \fB0\fR.
  288. For \fBx\fR or \fBX\fR conversions, \fB0x\fR or \fB0X\fR (respectively)
  289. will be added to the beginning of the result unless it is zero.
  290. For all floating-point conversions (\fBe\fR, \fBE\fR, \fBf\fR,
  291. \fBg\fR, and \fBG\fR) it guarantees that the result always 
  292. has a decimal point.
  293. For \fBg\fR and \fBG\fR conversions it specifies that 
  294. trailing zeroes should not be removed.
  295. .PP
  296. The third portion of a conversion specifier is a number giving a
  297. minimum field width for this conversion.
  298. It is typically used to make columns line up in tabular printouts.
  299. If the converted argument contains fewer characters than the
  300. minimum field width then it will be padded so that it is as wide
  301. as the minimum field width.
  302. Padding normally occurs by adding extra spaces on the left of the
  303. converted argument, but the \fB0\fR and \fB\-\fR flags 
  304. may be used to specify padding with zeroes on the left or with
  305. spaces on the right, respectively.
  306. If the minimum field width is specified as \fB*\fR rather than
  307. a number, then the next argument to the \fBformat\fR command
  308. determines the minimum field width; it must be a numeric string.
  309. .PP
  310. The fourth portion of a conversion specifier is a precision,
  311. which consists of a period followed by a number.
  312. The number is used in different ways for different conversions.
  313. For \fBe\fR, \fBE\fR, and \fBf\fR conversions it specifies the number
  314. of digits to appear to the right of the decimal point.
  315. For \fBg\fR and \fBG\fR conversions it specifies the total number
  316. of digits to appear, including those on both sides of the decimal
  317. point (however, trailing zeroes after the decimal point will still
  318. be omitted unless the \fB#\fR flag has been specified).
  319. For integer conversions, it specifies a mimimum number of digits
  320. to print (leading zeroes will be added if necessary).
  321. For \fBs\fR conversions it specifies the maximum number of characters to be 
  322. printed; if the string is longer than this then the trailing characters will be dropped.
  323. If the precision is specified with \fB*\fR rather than a number
  324. then the next argument to the \fBformat\fR command determines the precision;
  325. it must be a numeric string.
  326. .PP
  327. The fourth part of a conversion specifier is a length modifier,
  328. which must be \fBh\fR or \fBl\fR.
  329. If it is \fBh\fR it specifies that the numeric value should be
  330. truncated to a 16-bit value before converting.
  331. This option is rarely useful.
  332. The \fBl\fR modifier is ignored.
  333. .PP
  334. The last thing in a conversion specifier is an alphabetic character
  335. that determines what kind of conversion to perform.
  336. The following conversion characters are currently supported:
  337. .TP 10
  338. \fBd\fR
  339. Convert integer to signed decimal string.
  340. .TP 10
  341. \fBu\fR
  342. Convert integer to unsigned decimal string.
  343. .TP 10
  344. \fBi\fR
  345. Convert integer to signed decimal string;  the integer may either be
  346. in decimal, in octal (with a leading \fB0\fR) or in hexadecimal
  347. (with a leading \fB0x\fR).
  348. .TP 10
  349. \fBo\fR
  350. Convert integer to unsigned octal string.
  351. .TP 10
  352. \fBx\fR or \fBX\fR
  353. Convert integer to unsigned hexadecimal string, using digits
  354. ``0123456789abcdef'' for \fBx\fR and ``0123456789ABCDEF'' for \fBX\fR).
  355. .TP 10
  356. \fBc\fR
  357. Convert integer to the 8-bit character it represents.
  358. .TP 10
  359. \fBs\fR
  360. No conversion; just insert string.
  361. .TP 10
  362. \fBf\fR
  363. Convert floating-point number to signed decimal string of 
  364. the form \fIxx.yyy\fR, where the number of \fIy\fR's is determined by 
  365. the precision (default: 6).
  366. If the precision is 0 then no decimal point is output.
  367. .TP 10
  368. \fBe\fR or \fBe\fR
  369. Convert floating-point number to scientific notation in the 
  370. form \fIx.yyy\fBe\(+-\fIzz\fR, where the number of \fIy\fR's is determined 
  371. by the precision (default: 6).
  372. If the precision is 0 then no decimal point is output.
  373. If the \fBE\fR form is used then \fBE\fR is 
  374. printed instead of \fBe\fR.
  375. .TP 10
  376. \fBg\fR or \fBG\fR
  377. If the exponent is less than \-4 or greater than or equal to the 
  378. precision, then convert floating-point number as for \fB%e\fR or 
  379. \fB%E\fR.
  380. Otherwise convert as for \fB%f\fR.
  381. Trailing zeroes and a trailing decimal point are omitted.
  382. .TP 10
  383. \fB%\fR
  384. No conversion: just insert \fB%\fR.
  385. .LP
  386. For the numerical conversions the argument being converted must
  387. be an integer or floating-point string; format converts the argument
  388. to binary and then converts it back to a string according to 
  389. the conversion specifier.
  390.  
  391. .SH "DIFFERENCES FROM ANSI SPRINTF"
  392. .PP
  393. .VS
  394. The behavior of the format command is the same as the
  395. ANSI C \fBsprintf\fR procedure except for the following
  396. differences:
  397. .IP [1]
  398. \fB%p\fR and \fB%n\fR specifiers are not currently supported.
  399. .VE
  400. .IP [2]
  401. For \fB%c\fR conversions the argument must be a decimal string,
  402. which will then be converted to the corresponding character value.
  403. .IP [3]
  404. .VS
  405. The \fBl\fR modifier is ignored;  integer values are always converted
  406. as if there were no modifier present and real values are always
  407. converted as if the \fBl\fR modifier were present (i.e. type
  408. \fBdouble\fR is used for the internal representation).
  409. If the \fBh\fR modifier is specified then integer values are truncated
  410. to \fBshort\fR before conversion.
  411. .VE
  412.  
  413. .SH KEYWORDS
  414. conversion specifier, format, sprintf, string, substitution
  415.